package com.yanqu.road.server.manger.activity.monjinlottery.pb;

import com.yanqu.road.entity.activity.selectlottery.config.SelectLotteryConfig;
import com.yanqu.road.entity.activity.selectlottery.config.SelectLotteryGoodsConfig;
import com.yanqu.road.entity.activity.selectlottery.data.SelectLotteryUserData;
import com.yanqu.road.pb.activity.SelectLotteryProto;
import com.yanqu.road.server.manger.activity.monjinlottery.SelectLotteryMgr;

import java.util.Map;

public class SelectLotteryPb {

    /**
     * 构建商品配置
     * @param goodsConfig
     * @return
     */
    public static SelectLotteryProto.SelectLotteryGoodsConfig.Builder buildSelectLotteryGoodsConfig(SelectLotteryGoodsConfig goodsConfig) {
        SelectLotteryProto.SelectLotteryGoodsConfig.Builder builder = SelectLotteryProto.SelectLotteryGoodsConfig.newBuilder();
        builder.setActivityId(goodsConfig.getActivityId());
        builder.setId(goodsConfig.getId());
        builder.setName(goodsConfig.getName());
        builder.setRewards(goodsConfig.getRewards());
        builder.setWeights(goodsConfig.getWeights());
        builder.setSelectNum(goodsConfig.getSelectNum());
        builder.setIsShow(goodsConfig.getIsShow());
        builder.setIsNotice(goodsConfig.getIsNotice());
        builder.setSecondRewards(goodsConfig.getSecondRewards());
        builder.setQuality(goodsConfig.getQuality());
        return builder;
    }

    /**
     * 构建用户数据
     * @param userData
     * @return
     */
    public static SelectLotteryProto.SelectLotteryUserData.Builder buildSelectLotteryUserData(SelectLotteryUserData userData) {
        SelectLotteryConfig config = SelectLotteryMgr.getConfig(userData.getActivityId());
        SelectLotteryProto.SelectLotteryUserData.Builder builder = SelectLotteryProto.SelectLotteryUserData.newBuilder();
        builder.setActivityId(userData.getActivityId());
        builder.setUserId(userData.getUserId());
        builder.setSelectRewardId(userData.getSelectRewardId());
        builder.setReBigHitDrawNum(config.ROLL_BIG_GUARANTEE_TIMES - userData.getSeRewardNum());
        builder.setReSmallHitDrawNum(config.ROLL_GUARANTEE_NUM - userData.getDrawNum());
        builder.setLastEnterActivityTime(userData.getLastEnterTime());
        for (Map.Entry<Integer, Integer> entry : userData.getSelectNumMap().entrySet()) {
            builder.addSelectRewardNumData(buildSelectLotterySelectRewardNumData(entry.getKey(), entry.getValue()));
        }
        return builder;
    }

    /**
     * 构建选择奖励数量
     * @param id
     * @param num
     * @return
     */
    public static SelectLotteryProto.SelectLotterySelectRewardNumData.Builder buildSelectLotterySelectRewardNumData(int id, int num) {
        SelectLotteryProto.SelectLotterySelectRewardNumData.Builder builder = SelectLotteryProto.SelectLotterySelectRewardNumData.newBuilder();
        builder.setRewardId(id);
        builder.setSelectRewardNum(num);
        return builder;
    }
}
